
'use strict';

/**
	Zombie Navigator
	Copyright © 2015  Zombie Navigator Developers
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	
	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
	
	The latest version of the GNU AGPL should be available here:
	<https://www.gnu.org/licenses/agpl.html>
	
	
	== What's this? ==
	This is a Firefox addon. It has few GUI elements, however. In fact, it is
	mainly intended to run unattended with something like pseudo-headless
	`xvfb-run firefox`. On launch, if instructed to run a Zombie script, it
	runs that script inside a sandbox but do nothing otherwise. Please note that
	we only test the addon on a GNU/Linux system. Since it is designed as a
	pure-SDK addon, it may run under other platforms. In general, it should not
	do any harms there.
	
	
	== What's this for? (strength) ==
	* Run automated tests using existing Firefox profiles
	* Aimed to be more compatible and less intrusive than SlimerJS
	* Automate web tasks that has no API and requires a full web browser
	* Anything automatic that needs a real Firefox or a real web browser
	* Far simpler than Greasemonkey and requires no manual interaction
	* May also be useful for an advanced Firefox user
	* Any use case between SlimerJS and Greasemonkey
	* No code-level compatibility with PhantomJS or CasperJS
	* Pure JavaScript, no dependencies other than Firefox (unlike Selenium)
	* Trivially works out of the box with (possibly) the latest Firefox (by design)
	
	
	== How to use it ==
	Set a environment variable named 'ZOMBIE_NAVIGATOR_SCRIPT_PATH' pointing to
	the absolute path of the Zombie script you want to run.
	
	Or set ZOMBIE_NAVIGATOR_SCRIPT_PATH=<demo_ID> to see demos.
	
	If it cannot find such a variable, this addon does not do anything.
	
	
	== How does it work? ==
	Please see the source code.
	
	A Zombie script runs inside a sandbox, so it does not have the privileges
	the addon itself has. It cannot do `require ('chrome')` or even
	`require ('sdk/page-mod')`. It can only access the Zombie API, using the
	CommonJS environment the SDK provides. However this addon has limited
	control over its execution since the addon is purely written with the Addon
	SDK. (XXX: We want more strong API, Mozilla! Because we choose *Firefox*,
	not Google Chrome!)
	
	A Zombie script can open a new window. It can then manipulate tabs on that
	window. But it SHALL NOT access any other windows. (TODO: Zombie-controlled
	windows should indicate as such) As a rule, a Zombie script has no access
	to anything that is not explicitly under its control.
	
	Zombie scripts must not have access to persistent storages or local files.
	They are not allowed to enumerate windows or tabs including those under the
	scripts' control.
	
	
	== About License ==
	Though this program is not a web application, we choose GNU AGPL because it
	provides the maximum freedom to the users even when it is embedded in a
	SaaS product. When a new version of the GNU AGPL is released, we will
	normally start to release newer version of this program under that
	new version of the license, unless we decide otherwise. License terms of
	already released versions are not affected.
	
	
	== Coding (PLEASE READ) ==
	We use UTF-8 as the preferred text encoding whenever possible.
	
	Indentations use a single tab (U+0009) and each represents 4 spaces.
	
	We also care about consistency of coding styles.
	
	ES5 strict mode is preferred. We use some of the ES6 features since this
	code is Firefox 38+ only, in which case we prefer the ES6 ways over older
	ones.
	
	This addon is meant to be ESR-compatible. We always suport the latest ESR
	version and later release versions. We try to accomodate the older ESR
	version until the next ESR version is widely deployed. But otherwise we
	want to drop support for older versions. Our policy is drop support for
	such old versions on every release even if no strong reason to do so exists.
	
	We are trying to do things with pure SDK (no chrome access), but this may
	turn to be imposssible (since SDK is incomplete, not strong enough and
	sometimes buggy especially when we try to do complex things). Addon SDK,
	for example, does not have an event which is emitted just after the DOM is
	initialized, but before any scripts on the page run. Unlike Google Chrome,
	we want Firefox to support really complex and non-trivial addons. We believe
	addons are not just for "fancy things" but for doing truly innovative
	things, which require strong and complete APIs.
	
	We want this addon to be multiprocess-compatible. The SDK, however, does
	not seem perfectly compatible with multiprocess Firefox yet. We do not use
	Low-Level APIs related to Contents, but things break. (SDK throws
	internally)
	
	Localization is of a low priority.
	
	If this addon is problematic on Microsoft Windows, we can happily drop
	support for it explicitly. In that case we may include "winnt" in
	system-blacklist.json so that if installed on WINNT the addon refuses to
	run. Signing requirement makes it impossible to fool this mechanism.
	
	Clone via git: https://notabug.org/desktopd/zombie-navigator
	
	
	@file
	@license AGPL-3.0+
*/


/*
	Should print nothing unless there is an error
	e.g. dump, zombie.print, console.*, ...
*/
try {
	require('./utils/input').acceptInput();
	
	const scriptURI = require('./utils/system').getScriptURI();
	if (false === scriptURI) {
		// do nothing!
		require('./utils/help').showHelpIfNecessary();
	} else {
		require('./utils/script-loader').runScript(scriptURI);
	}
} catch (e) {
	require('./utils/error').print(e);
}


// vim: ts=4 noet ai

